* remove "\r" nonsense
[mascara-docs.git] / C / sorting.and.searching.cormen.algo / Introduction to Algorithms, Third Edition / code / rbtr.h
blobf9c188963ee803c53a56eb187b04fcc77abfe330
1 #ifndef RBT_H
2 #define RBT_H
4 typedef enum {
5 RBT_STATUS_OK,
6 RBT_STATUS_MEM_EXHAUSTED,
7 RBT_STATUS_DUPLICATE_KEY,
8 RBT_STATUS_KEY_NOT_FOUND
9 } RbtStatus;
11 typedef void *RbtIterator;
12 typedef void *RbtHandle;
14 RbtHandle rbtNew(int(*compare)(void *a, void *b));
15 // create red-black tree
16 // parameters:
17 // compare pointer to function that compares keys
18 // return 0 if a == b
19 // return < 0 if a < b
20 // return > 0 if a > b
21 // returns:
22 // handle use handle in calls to rbt functions
25 void rbtDelete(RbtHandle h);
26 // destroy red-black tree
28 RbtStatus rbtInsert(RbtHandle h, void *key, void *value);
29 // insert key/value pair
31 RbtStatus rbtErase(RbtHandle h, RbtIterator i);
32 // delete node in tree associated with iterator
33 // this function does not free the key/value pointers
35 RbtIterator rbtNext(RbtHandle h, RbtIterator i);
36 // return ++i
38 RbtIterator rbtBegin(RbtHandle h);
39 // return pointer to first node
41 RbtIterator rbtEnd(RbtHandle h);
42 // return pointer to one past last node
44 void rbtKeyValue(RbtHandle h, RbtIterator i, void **key, void **value);
45 // returns key/value pair associated with iterator
47 RbtIterator rbtFind(RbtHandle h, void *key);
48 // returns iterator associated with key
50 #endif